package ch.ethz.inf.shop.model;

import java.sql.ResultSet;
import java.sql.SQLException;

import ch.ethz.inf.shop.Title;
import ch.ethz.inf.shop.model.simpleDatabase.Tuple;

/**
 * This class represents a Brand of products (i.e. Nestle, Barilla etc)
 */
public final class Brand {

	@Override
	public String toString() {
		return name;
	}

	@Title(text = "Brand Name", isVisible = true)
	private final String name;
	@Title(text = "Brand ID", isVisible = false)
	private final int brandId;

	public Brand(String name, int brandId) {
		super();
		this.name = name;
		this.brandId = brandId;
	}

	public Brand(final ResultSet rs) throws SQLException {
		this.brandId = rs.getInt("brand_id");
		this.name = rs.getString("brand_name");
	}

	public Brand(final Tuple tuple) {
		this.brandId = tuple.getInt("brand.brand_id");
		this.name = tuple.getString("brand.name");

	}

	public String getName() {
		return name;
	}

	public int getBrandId() {
		return brandId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + brandId;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Brand other = (Brand) obj;
		if (brandId != other.brandId)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

}
